<template>
    <div>
        <router-view/>
    </div>
</template>

<script setup>
import { useUserStore } from "@/stores/user/user";
const user = useUserStore()
import { onBeforeMount } from "vue";
import loginApi from "@/http/login/loginApi";
import router from "@/router";
import { ElMessage } from "element-plus";
import { useAllStore } from "@/stores/all";
const all = useAllStore()
// 自动登录
onBeforeMount(()=>{
    if (user.getToken!==null && user.getToken !== "" && user.getToken!==undefined) {
        loginApi.post("get_token").then((res)=>{
            if (res["msg"]) {
                user.setInfo("identity",res["info"])
                all.setCoursesVue("topChoose",res["info"]==='teacher'?0:1)
                user.setIsLogin(true)
            }else {
                router.push("/login")
            }
        }).catch(()=>{
            router.push("/login")
        })
    }else {
        ElMessage('你来了啊,记得先选好登录端口')
        router.push("/login")
    }
})
</script>

<style scoped>

</style>